<?php

namespace App;

use App\Storages\KeyStorageInterface;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;

final class Concept
{
    private Client $client;
    private KeyStorageInterface $keyStorage;

    public function __construct(KeyStorageInterface $keyStorage)
    {
        $this->client = new Client();
        $this->keyStorage = $keyStorage;
    }

    public function getUserData()
    {
        $params = [
            'auth' => ['user', 'pass'],
            'token' => $this->keyStorage->getSecretKey()
        ];
        $request = new Request('GET', 'https://jsonplaceholder.typicode.com/users', $params);
        $promise = $this->client
            ->sendAsync($request)
            ->then(function ($response) {
                return $response->getBody()->getContents();
            });

        return $promise->wait();
    }
}
